package com.spsoft.system.controller;

import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.controller.BaseController;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.system.model.vo.LoginUserVo;
import com.spsoft.system.model.vo.RefreshTokenVo;
import com.spsoft.system.model.vo.SysRolesVo;
import com.spsoft.system.service.SysLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"登录相关 "})
@RestController
@RequestMapping("/login")
@RequiredArgsConstructor
@Validated
@Slf4j
public class LoginController extends BaseController {

    private final SysLoginService sysLoginService;

    @ApiOperation("获取菜单和用户信息")
    @AnonymousAccess(value = "/getMenu", method = RequestMethod.POST,permissionCode = "VMS_INVOICE")
    @Log(value = "获取菜单和用户信息", type = LogActionType.SELECT,  menuName = LogMenuEnum.LOGIN)
    public Result<LoginUserVo> getMenu() {
        return sysLoginService.getMenu();
    }

    @ApiOperation("刷新令牌")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reToken", value = "reToken第一次可不填写", dataTypeClass = String.class, dataType = "String", paramType = "query"),
    })
    @AnonymousAccess(value = "/refreshToken", method = RequestMethod.POST,permissionCode = "VMS_INVOICE")
    @Log(value = "刷新令牌", type = LogActionType.SELECT,  menuName = LogMenuEnum.LOGIN)
    public Result<RefreshTokenVo> refreshToken(@RequestParam(required = false) String reToken) {
        return sysLoginService.refreshToken(reToken);
    }
}
